#include "StdAfx.h"
#include ".\joyudpdatalist.h"

//##ModelId=44C4B6170149
JoyUDPDataList::JoyUDPDataList(void)
{
}

//##ModelId=44C4B617014B
JoyUDPDataList::~JoyUDPDataList(void)
{
	removeAllData();
}
//##ModelId=44C4B617014D
void JoyUDPDataList::addToList(GAME_UDP_DATA datanode)
{
	m_GameUDPDataListLock.Lock();
	m_GameUDPDataList.push_back(datanode);
	m_GameUDPDataListLock.Unlock();
}
//##ModelId=44C4B6170158
bool JoyUDPDataList::findDataInList(GAME_UDP_DATA *datanode,u_short uPort)
{
	bool bRet;
    GAME_UDP_DATA nodedata;
	m_GameUDPDataListLock.Lock();
	std::list<GAME_UDP_DATA >::iterator it = m_GameUDPDataList.begin();
	std::list<GAME_UDP_DATA >::iterator e = m_GameUDPDataList.end();
	bRet=false;
	for(; it != e; ++ it)
	{
		nodedata = *it;
		if(nodedata.iPort==uPort) 
		{
			bRet=true;
			datanode->iDataLen=nodedata.iDataLen;
			datanode->iPort=nodedata.iPort;
			memcpy(datanode->sBuf,nodedata.sBuf,nodedata.iDataLen);
			m_GameUDPDataList.erase(it);				
			break;
				
		}
	}	
	m_GameUDPDataListLock.Unlock();

	return bRet;


}
//##ModelId=44C4B617015C
bool JoyUDPDataList::ListIsNotNull()
{
	if(m_GameUDPDataList.size()>0) return true;
	else return false;
}
//##ModelId=44C4B617015B
void JoyUDPDataList::removeAllData()
{
	m_GameUDPDataListLock.Lock();
	m_GameUDPDataList.clear();
	m_GameUDPDataListLock.Unlock();

}
